package com.event.binlog.listener;

import com.event.binlog.iface.IBinlogRowEventHandle;
import com.event.common.model.BinglogAddEvent;
import com.event.common.model.BinglogDelEvent;
import com.event.common.model.BinglogUpdateEvent;
import com.google.common.eventbus.Subscribe;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
@Slf4j
public class BinlogRowEventListener {

    private List<IBinlogRowEventHandle> binlogRowEventHandles;

    public BinlogRowEventListener(List<IBinlogRowEventHandle> binlogRowEventHandles){
        this.binlogRowEventHandles = binlogRowEventHandles;
    }

    @Subscribe
    public void handle(BinglogAddEvent event){
        binlogRowEventHandles.forEach(binlogRowEventHandle -> {
            try {
                binlogRowEventHandle.handle(event);
            }catch (Exception e){
                log.warn("处理binlog事件异常",e);
            }
        });
    }

    @Subscribe
    public void handle(BinglogDelEvent event){
        binlogRowEventHandles.forEach(binlogRowEventHandle -> {
            try {
                binlogRowEventHandle.handle(event);
            }catch (Exception e){
                log.warn("处理binlog事件异常",e);
            }
        });
    }

    @Subscribe
    public void handle(BinglogUpdateEvent event){
        binlogRowEventHandles.forEach(binlogRowEventHandle -> {
            try {
                binlogRowEventHandle.handle(event);
            }catch (Exception e){
                log.warn("处理binlog事件异常",e);
            }
        });
    }
}
